﻿using Abp.Application.Services;
using Abp.Collections.Extensions;
using Abp.Domain.Repositories;
using Abp.Extensions;
using Abp.Runtime.Session;
using Aug.iot.Authorization;
using Aug.iot.Authorization.Roles;
using Aug.iot.Authorization.Users;
using Aug.iot.Tasks.Dtos;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using Abp.Linq.Extensions;
using System.Text;
using Abp.Authorization;

namespace Aug.iot.Tasks
{
    [AbpAuthorize(PermissionNames.Pages_Users)]
    public class TaskAppService : AsyncCrudAppService<Task, TaskDto, int, PagedTaskResultRequestDto, CreateTaskDto, TaskDto>, ITaskAppService
    {

        public TaskAppService(IRepository<Task, int> repository)
            : base(repository)
        {
        }

        protected override IQueryable<Task> CreateFilteredQuery(PagedTaskResultRequestDto input)
        {
            return Repository.GetAllIncluding(x=> x.AssignedPerson)
                .WhereIf(!input.Keyword.IsNullOrWhiteSpace(), x => x.Title.Contains(input.Keyword) || x.Description.Contains(input.Keyword))
                .WhereIf(input.State.HasValue, x => x.State == input.State);
        }
    }
}
